//
//  KWNQuestionFinishViewController.m
//  KWNClient
//
//  Created by 张明磊 on 14/10/17.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "KWLWaitQuestionViewController.h"
#import "Model_question.h"
#import "JDGroupedFlipNumberView.h"
#import "MLBlackTransition.h"
#import "Model_question.h"
#import "MINavigationController.h"
#import "Model_questionList.h"
#import "UIButton+WebCache.h"
#import "KWNNetwork.h"
#import "KWNPhotoDetailViewController.h"
#import "KWLLoginViewController.h"
#import "KWNFeedbackViewController.h"

typedef NS_ENUM(NSInteger, KWNQDetailCellTag)
{
    KWNQDetailCellTag_caina_r       = 100,
    KWNQDetailCellTag_viewBack             ,
    KWNQDetailCellTag_clickCaiNa           ,
    KWNQDetailCellTag_cainaAlter           ,
    KWNQDetailCellTag_loginOut             ,
    KWNQDetailCellTag_imageOne           ,
    KWNQDetailCellTag_imageTwo           ,
    KWNQDetailCellTag_huida                  ,
};


@interface KWLWaitQuestionViewController ()<UITableViewDataSource,UITableViewDelegate,MWPhotoBrowserDelegate,UITextViewDelegate,UIActionSheetDelegate>

@property (strong, nonatomic) Model_questionList *model_list;

@property (weak, nonatomic) UIButton *button_cancel;
@property (weak, nonatomic) UITextView *textView_input;

@property (weak, nonatomic) UIView *view_input;

@property (strong, nonatomic) NSArray *array_location;

@property (strong, nonatomic) NSMutableArray *array_photo;

@end

@implementation KWLWaitQuestionViewController

- (id)initWithModel:(Model_questionList *)model_list{
    self = [super init];
    if(self){
        _model_list = model_list;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *array_tmp = @[
                           @"北京",@"上海",@"天津",@"重庆",@"黑龙江省",@"吉林省",@"辽宁省",@"河北省",@"山西省",@"内蒙古自治区",@"山东省",@"安徽省",@"江苏省",@"浙江省",@"江西省",@"福建省",@"河南省",@"湖北省",@"湖南省",@"广东省",@"广西壮族自治区",@"海南省",@"四川省",@"贵州省",@"云南省",@"西藏自治区",@"陕西省",@"甘肃省",@"青海省",@"宁夏回族自治区",@"新疆维吾尔自治区",@"香港特别行政区",@"澳门特别行政区",@"台湾省"];
    _array_location = array_tmp;
    [self UI_QDetail];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"WaitQuestionPage"];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"WaitQuestionPage"];
}


- (void)UI_QDetail{
    //[self.navigationController enabledMLBlackTransition:NO];
    
    self.view.backgroundColor = RGB(239, 239, 244);
    
    UIView *imageView_title = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44 + IOS7_SIZE)];
    imageView_title.backgroundColor = RGB(91, 165, 229);
    [self.view addSubview:imageView_title];
    
    UILabel *label_title = [[UILabel alloc] initWithFrame:CGRectMake(imageView_title.frame.origin.x,IOS7_SIZE + 5,imageView_title.frame.size.width,35)];
    label_title.backgroundColor = [UIColor clearColor];
    label_title.textColor = RGB(63, 119, 167);
    label_title.textAlignment = NSTextAlignmentCenter;
    label_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0f];
    [self.view addSubview:label_title];
    label_title.text = @"问题详情";
    
    UITableView *tableView_home = [[UITableView alloc] initWithFrame:CGRectMake(imageView_title.frame.origin.x, imageView_title.frame.origin.y + imageView_title.frame.size.height, imageView_title.frame.size.width, self.view.frame.size.height - imageView_title.frame.size.height)];
    tableView_home.backgroundColor = [UIColor clearColor];
    tableView_home.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView_home.delegate = self;
    tableView_home.dataSource = self;
    [self.view addSubview:tableView_home];
    
    UIButton *button_menu = [UIButton buttonWithType:UIButtonTypeCustom];
    button_menu.frame = CGRectMake(0, IOS7_SIZE, 60, 45);
    [button_menu setImage:[UIImage imageFileName:@"button_back.png"] forState:UIControlStateNormal];
    [button_menu addTarget:self action:@selector(didClickButton_questionD:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_menu];
    button_menu.tag = KWNQDetailCellTag_viewBack;
    
    UIImageView *imageView_huida = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 63, 320, 65)];
    imageView_huida.image = [UIImage imageFileName:@"image_pinglunBack.png"];
    [self.view addSubview:imageView_huida];
    
    UIButton *button_huida = [UIButton buttonWithType:UIButtonTypeCustom];
    button_huida.frame = CGRectMake(10, imageView_huida.frame.origin.y + 9, 300, 45);
    button_huida.backgroundColor = RGB(91, 165, 229);
    [button_huida setTitle:@"开始回答" forState:UIControlStateNormal];
    button_huida.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
    [button_huida addTarget:self action:@selector(didClickButton_questionD:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_huida];
    button_huida.layer.cornerRadius = 3.0;
    button_huida.tag = KWNQDetailCellTag_huida;
    
    UIButton *button_edit = [UIButton buttonWithType:UIButtonTypeCustom];
    button_edit.frame = CGRectMake(250, IOS7_SIZE, 60, 45);
    [button_edit setTitle:@"举报" forState:UIControlStateNormal];
    [button_edit setTitleColor:RGB(63, 119, 167) forState:UIControlStateNormal];
    button_edit.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    [button_edit addTarget:self action:@selector(waitQuestionReportBtn_click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button_edit];
    
}

#pragma mark - 举报按钮点击 -

- (void)waitQuestionReportBtn_click:(id)sender
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"举报问题"
                                  delegate:self
                                  cancelButtonTitle:@"取消"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles:@"问题属广告信息、敏感政治内容或其他违规内容", @"手动填写",nil];
    actionSheet.tag = 100;
    [actionSheet showInView:self.view];
}
#pragma mark - UIActionSheetDelegate -


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    //NSLog(@"%i", buttonIndex);
    
    NSString *buttontitle = [actionSheet buttonTitleAtIndex:buttonIndex];
    if (buttonIndex == actionSheet.cancelButtonIndex) {
        return;
    }
    switch (buttonIndex) {
        case 0:
        {
// CS 快法务 KLW 2014-12-24
//            [UIUtils view_showProgressHUD:@"加载中,请稍候..." inView:self.view withType:0];
//            
            [SVProgressHUD showWithStatus:@"加载中,请稍候..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
            [[KWNNetwork sharedInstance]reportWithQuestionId:_model_list.string_id andReportStr:buttontitle FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//                [UIUtils view_hideProgressHUDinView:self.view];
//                
// DE 快法务 KLW 2014-12-24
                switch (stateCode) {
                    case 10000:
                    {
// CS 快法务 KLW 2014-12-24
//                        [UIUtils view_showProgressHUD:@"您的举报信息提交成功" inView:self.view withTime:1.5f];
//                        
                        [SVProgressHUD dismissWithSuccess:@"您的举报信息提交成功" afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                    }
                        break;
                    case 10003:
                    {
// AS 快法务 KLW 2014-12-24
                        [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                        UIAlertView *alter_login;
                        if(IOS8_VERSION){
                            alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        }
                        else{
                            alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        }
                        alter_login.tag = 10003;
                        [alter_login show];
                        
                    }
                        break;
                    default:
                    {
                        NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                        [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                        
                        [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                    }
                        break;
                }
            }];
        }
            break;
        case 1:
        {
            KWNFeedbackViewController *feedbackControl = [[KWNFeedbackViewController alloc] initWithQid:_model_list.string_id];
            [self pushViewController:feedbackControl];
        }
            break;
        default:
        {
        }
            break;
    }
}

#pragma mark - 点击问题详情页按钮 -
/**
 *  点击问题详情页按钮
 */
- (void)didClickButton_questionD:(UIButton *)button{
    switch (button.tag) {
        case KWNQDetailCellTag_viewBack:{
            NSMutableArray *array_image = [Model_question sharedInstance].array_imagePath;
            for(int i; i<array_image.count; i++){
                NSString *string_imageDir = array_image[i];
                NSFileManager *fileManager = [NSFileManager defaultManager];
                [fileManager removeItemAtPath:string_imageDir error:nil];
            }
            [Model_question sharedInstance].string_text = nil;
            [Model_question sharedInstance].array_imagePath = nil;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"Notification_KWNReloadAtFinish" object:nil];
            if(IOS7_VERSION){
                [self.navigationController enabledMLBlackTransition:YES];
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
            else{
                [self.navigationController_MI popToRootViewControllerAnimated:YES];
            }
        }break;
        case KWNQDetailCellTag_huida:{
            if(_view_input){
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                [UIView setAnimationDuration:0.2f];
                [UIView setAnimationRepeatCount:1];
                [UIView setAnimationBeginsFromCurrentState:YES];
                _button_cancel.alpha = 0.6;
                [UIView commitAnimations];
                
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                [UIView setAnimationDuration:0.3f];
                [UIView setAnimationRepeatCount:1];
                [UIView setAnimationBeginsFromCurrentState:YES];
                _view_input.frame = CGRectMake(0, Iphone5_size(150, 44 + IOS7_SIZE), 320, _view_input.frame.size.height);
                [UIView commitAnimations];
                
                [_textView_input becomeFirstResponder];
            }
            else{
                UIButton *button_backCancel = [UIButton buttonWithType:UIButtonTypeCustom];
                button_backCancel.frame = self.view.frame;
                button_backCancel.backgroundColor = [UIColor blackColor];
                button_backCancel.alpha = 0;
                [button_backCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [button_backCancel addTarget:self action:@selector(didClickButton_cancel:) forControlEvents:UIControlEventTouchUpInside];
                [self.view addSubview:button_backCancel];
                _button_cancel = button_backCancel;
                
                UIView *view_input = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 200 + Iphone5_size(20, 0))];
                view_input.backgroundColor = RGB(239,239,244);
                [self.view addSubview:view_input];
                _view_input = view_input;
                
                UIView *view_board = [[UIView alloc] initWithFrame:CGRectMake(10, 50, view_input.frame.size.width - 20, view_input.frame.size.height - Iphone5_size(120, 100))];
                view_board.backgroundColor = [UIColor whiteColor];
                view_board.layer.cornerRadius = 6.0;
                view_board.layer.borderWidth = 1.0;//边框宽度
                view_board.layer.borderColor = RGB(197, 197, 197).CGColor;//边框颜色
                [view_input addSubview:view_board];
                //_view_input = view_input;
                
                UITextView *textView_input = [[UITextView alloc] initWithFrame:CGRectMake(20, view_board.frame.origin.y, view_board.frame.size.width - 20, view_board.frame.size.height)];
                textView_input.backgroundColor = [UIColor clearColor];
                textView_input.textColor = RGB(107, 107, 107);
                textView_input.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
                textView_input.autocorrectionType = UITextAutocorrectionTypeNo;
                textView_input.autocapitalizationType = UITextAutocapitalizationTypeNone;
                textView_input.returnKeyType = UIReturnKeyDefault;
                textView_input.delegate = self;
                [view_input addSubview:textView_input];
                //textView_input.delegate = self;
                //_textView_content = textView_input;
                //textView_input.tag = 100;
                [textView_input becomeFirstResponder];
                _textView_input = textView_input;

                UILabel *label_title = [[UILabel alloc] initWithFrame:CGRectMake(110, 15, 100, 20)];
                label_title.backgroundColor = [UIColor clearColor];
                label_title.text = @"我的回答";
                label_title.textColor = RGB(107, 107, 107);
                label_title.textAlignment = NSTextAlignmentCenter;
                label_title.font = [UIFont fontWithName:@"Helvetica-Bold" size:18.0f];
                [view_input addSubview:label_title];
                
                UIButton *button_cancel = [UIButton buttonWithType:UIButtonTypeCustom];
                button_cancel.frame = CGRectMake(10, label_title.frame.origin.y, 50, 20);
                button_cancel.backgroundColor = [UIColor clearColor];
                button_cancel.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
                [button_cancel setTitle:@"取消" forState:UIControlStateNormal];
                [button_cancel setTitleColor:RGB(107, 107, 107) forState:UIControlStateNormal];
                [button_cancel addTarget:self action:@selector(didClickButton_cancel:) forControlEvents:UIControlEventTouchUpInside];
                [view_input addSubview:button_cancel];
                
                UIButton *button_send = [UIButton buttonWithType:UIButtonTypeCustom];
                button_send.frame = CGRectMake(260, label_title.frame.origin.y, 50, 20);
                button_send.backgroundColor = [UIColor clearColor];
                button_send.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
                [button_send setTitle:@"发送" forState:UIControlStateNormal];
                [button_send setTitleColor:RGB(92, 166, 229) forState:UIControlStateNormal];
                [button_send addTarget:self action:@selector(didClickButton_send:) forControlEvents:UIControlEventTouchUpInside];
                [view_input addSubview:button_send];
                
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                [UIView setAnimationDuration:0.3f];
                [UIView setAnimationRepeatCount:1];
                [UIView setAnimationBeginsFromCurrentState:YES];
                view_input.frame = CGRectMake(0, Iphone5_size(150, 44 + IOS7_SIZE), 320, view_input.frame.size.height);
                [UIView commitAnimations];
                
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
                [UIView setAnimationDuration:0.2f];
                [UIView setAnimationRepeatCount:1];
                [UIView setAnimationBeginsFromCurrentState:YES];
                button_backCancel.alpha = 0.6;
                [UIView commitAnimations];
            }
        }break;
        default:
            break;
    }
}

#pragma mark - 点击取消按钮 -
/**
 *  点击取消按钮
 */
- (void)didClickButton_cancel:(UIButton *)button_cancel{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationBeginsFromCurrentState:YES];
    _view_input.frame = CGRectMake(0, self.view.frame.size.height, 320, _view_input.frame.size.height);
    [UIView commitAnimations];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2f];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationBeginsFromCurrentState:YES];
    _button_cancel.alpha = 0;
    [UIView commitAnimations];
    
    [self.view endEditing:YES];
}

#pragma mark - UITextViewDelegate -

//-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
//{
//    if ([text isEqualToString:@"\n"]) {
//        [textView resignFirstResponder];
//        [self didClickButton_cancel:nil];
//        return NO;
//    }
//    return YES;
//}

#pragma mark - 回答问题 -
/**
 *  回答问题
 */
- (void)didClickButton_send:(UIButton *)button_send{
    [self didClickButton_cancel:nil];
    if(_textView_input.text && _textView_input.text.length != 0){
// CS 快法务 KLW 2014-12-24
//        [UIUtils view_showProgressHUD:@"发送中..." inView:self.view withType:0];
//        
        [SVProgressHUD showWithStatus:@"发送中..." maskType:SVProgressHUDMaskTypeClear];
// CE 快法务 KLW 2014-12-24
        [[KWNNetwork sharedInstance] send_answerQuestion:_model_list.string_id andText:_textView_input.text FinishBlock:^(NSInteger stateCode, NSMutableArray *result) {
// DS 快法务 KLW 2014-12-24
//            [UIUtils view_hideProgressHUDinView:self.view];
//            
// DE 快法务 KLW 2014-12-24
            switch (stateCode) {
                case 10000:{
                    NSString *string_msg  = result[0];
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"notificaition_KWLReloadHome" object:nil];
// CS 快法务 KLW 2014-12-24
//                    [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                    
                    [SVProgressHUD dismissWithSuccess:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                    double delayInSeconds = 1.5;
                    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                        [self.navigationController popToRootViewControllerAnimated:YES];
                    });
                }break;
                case 10003:{
// AS 快法务 KLW 2014-12-24
                    [SVProgressHUD dismiss];
// AE 快法务 KLW 2014-12-24
                    UIAlertView *alter_login;
                    if(IOS8_VERSION){
                        alter_login = [[UIAlertView alloc] initWithTitle:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    }
                    else{
                        alter_login = [[UIAlertView alloc] initWithTitle:nil message:@"您的来问律师账号已在其它地方登录，请您重新登录此设备。如果不是您的操作，您的密码可能已泄露，请及时更改密码，或联系快问律师客服邮箱laiwenlvshi@kuaifawu.com。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    }
                    alter_login.tag = 10003;
                    [alter_login show];

//                    NSString *string_msg  = result[0];
//                    [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                    
//                    double delayInSeconds = 1.5;
//                    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
//                    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//                        //code to be executed on the main queue after delay
//                        KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
//                        [self pushViewController:login];
//                    });
                    //[self ]
                }break;

                default:{
                    NSString *string_msg  = result[0];
// CS 快法务 KLW 2014-12-24
//                    [UIUtils view_showProgressHUD:string_msg inView:self.view withTime:1.5f];
//                    
                    [SVProgressHUD dismissWithError:string_msg afterDelay:1.5];
// CE 快法务 KLW 2014-12-24
                }break;
            }
        }];
    }
    else{
// CS 快法务 KLW 2014-12-24
//        [UIUtils view_showProgressHUD:@"回答内容不能为空!" inView:self.view withTime:1.5f];
//        
        [SVProgressHUD showErrorWithStatus:@"回答内容不能为空!" duration:1.5];
// CE 快法务 KLW 2014-12-24
    }
    //[self.view endEditing:YES];
}

#pragma mark - alertView -
/**
 *  账号被替换下线
 */
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (alertView.tag) {
            //账号替换
        case 10003:{
            KWLLoginViewController *login = [[KWLLoginViewController alloc] initWithTag:6];
            [self pushViewController:login];
        }break;
            
        default:
            break;
    }
}


/**
 *  列表数据源
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell_waitQuestion";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil){
        cell = [[UITableViewCell alloc] init];
        //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UITextView *textView_content = [[UITextView alloc] initWithFrame:CGRectMake(10, 60, 280, 200)];
        textView_content.backgroundColor = [UIColor clearColor
                                            ];
        textView_content.text = _model_list.string_content;
        textView_content.textColor = RGB(93, 93, 93);
        textView_content.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
        textView_content.textAlignment = NSTextAlignmentJustified;
        textView_content.autocorrectionType = UITextAutocorrectionTypeNo;
        textView_content.autocapitalizationType = UITextAutocapitalizationTypeNone;
        textView_content.scrollEnabled = NO;
        [textView_content setEditable:NO];
        
        CGSize size_text = [self contentSizeOfTextView:textView_content];
        textView_content.frame = CGRectMake(textView_content.frame.origin.x, textView_content.frame.origin.y, size_text.width, size_text.height);
        
        UIView *view_b = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, textView_content.frame.size.height + 100)];
        if(_model_list.array_img_small && _model_list.array_img_small.count != 0){
            view_b.frame = CGRectMake(view_b.frame.origin.x, view_b.frame.origin.y, view_b.frame.size.width, view_b.frame.size.height + 51);
        }
        view_b.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:view_b];
        //设置矩形四个圆角半径
        view_b.layer.cornerRadius = 5.0;
        view_b.layer.borderWidth = 1.0;//边框宽度
        view_b.layer.borderColor = RGB(198, 198, 198).CGColor;//边框颜色
        [cell addSubview:view_b];
        [view_b addSubview:textView_content];
        
        UIImageView *imageview_wen = [[UIImageView alloc] initWithFrame:CGRectMake(13, 13, 20, 20)];
        imageview_wen.image = [UIImage imageFileName:@"wen.png"];
        [view_b addSubview:imageview_wen];

        UIImageView *imageView_user = [[UIImageView alloc] initWithFrame:CGRectMake(imageview_wen.frame.origin.x + imageview_wen.frame.size.width + 8, imageview_wen.frame.origin.y + 3, 12, 14)];
        imageView_user.image = [UIImage imageFileName:@"image_free_Person.png"];
        [view_b addSubview:imageView_user];
        
        UILabel *label_name = [[UILabel alloc] initWithFrame:CGRectMake(imageView_user.frame.origin.x + imageView_user.frame.size.width + 15, imageView_user.frame.origin.y + 5, 100, 20)];
        label_name.backgroundColor = [UIColor clearColor];
        NSInteger kind_areaName = _model_list.string_area.integerValue;
        NSString *string_name = _array_location[kind_areaName];
        label_name.text = [NSString stringWithFormat:@"%@网友",string_name];
        label_name.textColor = RGB(209, 209, 209);
        label_name.textAlignment = NSTextAlignmentLeft;
        label_name.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
        [cell addSubview:label_name];
        
        UIView *view_one = [[UIView alloc] initWithFrame:CGRectMake(imageview_wen.frame.origin.x , label_name.frame.origin.y + label_name.frame.size.height , 60, 20)];
        view_one.backgroundColor = RGB(253, 204, 67);
        [view_b addSubview:view_one];
        //设置矩形四个圆角半径
        view_one.layer.cornerRadius = 10.0;
        
        NSInteger kind = _model_list.string_kind.integerValue;
        UILabel *label_one = [[UILabel alloc] initWithFrame:view_one.frame];
        label_one.backgroundColor = [UIColor clearColor];
        if(kind < 10){
            label_one.text = @"个人问题";
        }
        else{
            label_one.text = @"公司问题";
        }
        label_one.textColor = RGB(200, 137, 46);
        label_one.textAlignment = NSTextAlignmentCenter;
        label_one.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
        [view_b addSubview:label_one];
        
        UIView *view_three = [[UIView alloc] initWithFrame:CGRectMake(view_one.frame.origin.x + view_one.frame.size.width + 5, view_one.frame.origin.y, 60, 20)];
        view_three.backgroundColor = RGB(253, 204, 67);
        [view_b addSubview:view_three];
        //设置矩形四个圆角半径
        view_three.layer.cornerRadius = 10.0;
        
        NSInteger kind_content = _model_list.string_kind.integerValue;
        UILabel *label_three = [[UILabel alloc] initWithFrame:view_three.frame];
        label_three.backgroundColor = [UIColor clearColor];
        switch (kind_content) {
            case 0:{
                label_three.text = @"婚姻家庭";
            }break;
            case 1:{
                label_three.text = @"房屋买卖";
            }break;
            case 2:{
                label_three.text = @"债务纠纷";
            }break;
            case 3:{
                label_three.text = @"劳动争议";
            }break;
            case 4:{
                label_three.text = @"交通肇事";
            }break;
            case 5:{
                label_three.text = @"刑事案件";
            }break;
            case 6:{
                label_three.text = @"其他类型";
            }break;
            case 11:{
                label_three.text = @"公司注册";
            }break;
            case 12:{
                label_three.text = @"投资融资";
            }break;
            case 13:{
                label_three.text = @"股权期权";
            }break;
            case 14:{
                label_three.text = @"合同事项";
            }break;
            case 15:{
                label_three.text = @"知识产权";
            }break;
            case 16:{
                label_three.text = @"财税事务";
            }break;
            case 17:{
                label_three.text = @"劳动人事";
            }break;
            case 18:{
                label_three.text = @"债务纠纷";
            }break;
            case 19:{
                label_three.text = @"其他问题";
            }break;
            default:
                break;
        }
        label_three.textColor = RGB(200, 137, 46);
        label_three.textAlignment = NSTextAlignmentCenter;
        label_three.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
        [view_b addSubview:label_three];
        
        if(_model_list.array_img_small.count == 1){
            UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
            button_photo.frame = CGRectMake(imageview_wen.frame.origin.x , textView_content.frame.origin.y + textView_content.frame.size.height + 5, 51, 51);
            button_photo.backgroundColor = [UIColor blackColor];
            [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:_model_list.array_img_small[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
            [view_b addSubview:button_photo];
            [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
            button_photo.tag = KWNQDetailCellTag_imageOne;
        }
        else if(_model_list.array_img_small.count == 2){
            UIButton *button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
            button_photo.frame = CGRectMake(imageview_wen.frame.origin.x , textView_content.frame.origin.y + textView_content.frame.size.height + 5, 51, 51);
            button_photo.backgroundColor = [UIColor blackColor];
            [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:_model_list.array_img_small[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            [button_photo addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
            [view_b addSubview:button_photo];
            [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
            button_photo.tag = KWNQDetailCellTag_imageOne;
            
            UIButton *button_addPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
            button_addPhoto.backgroundColor = [UIColor blackColor];
            button_addPhoto.frame = CGRectMake(button_photo.frame.origin.x + button_photo.frame.size.width + 10 , button_photo.frame.origin.y , 51, 51);
            [button_addPhoto sd_setBackgroundImageWithURL:[NSURL URLWithString:_model_list.array_img_small[1]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            [button_addPhoto addTarget:self action:@selector(didClickButton_addPhoto:)forControlEvents:UIControlEventTouchUpInside];
            [view_b addSubview:button_addPhoto];
            [button_addPhoto.imageView setContentMode:UIViewContentModeScaleAspectFit];
            button_addPhoto.tag = KWNQDetailCellTag_imageTwo;
        }
        
        UILabel *label_time = [[UILabel alloc] initWithFrame:CGRectMake(imageview_wen.frame.origin.x, view_b.frame.size.height - 12 - 13, 100, 12)];
        label_time.backgroundColor = [UIColor clearColor];
        label_time.text = _model_list.string_time;
        label_time.textColor = RGB(209, 209, 209);
        label_time.textAlignment = NSTextAlignmentLeft;
        label_time.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
        [view_b addSubview:label_time];
        
        UILabel *label_huida = [[UILabel alloc] initWithFrame:CGRectMake(view_b.frame.size.width - 100 - 13, label_time.frame.origin.y, 100, 12)];
        label_huida.backgroundColor = [UIColor clearColor];
        label_huida.text = [NSString stringWithFormat:@"%@个回答",_model_list.string_count];
        label_huida.textColor = label_time.textColor;
        label_huida.textAlignment = NSTextAlignmentRight;
        label_huida.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
        [view_b addSubview:label_huida];
        
        UILabel *label_tuisong = [[UILabel alloc] initWithFrame:CGRectMake(view_b.frame.origin.x, view_b.frame.origin.y + view_b.frame.size.height + 20, view_b.frame.size.width, 100)];
        label_tuisong.backgroundColor = [UIColor clearColor];
        label_tuisong.text = @"该问题目前无人回答\n抢首位回答可获最高10积分";
        label_tuisong.textColor = RGB(138, 138, 138);
        label_tuisong.textAlignment = NSTextAlignmentCenter;
        label_tuisong.numberOfLines = 10;
        label_tuisong.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
        [cell addSubview:label_tuisong];
    }
    return cell;
}

- (CGSize)contentSizeOfTextView:(UITextView *)textView{
    CGSize textViewSize = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, FLT_MAX)];
    return textViewSize;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITextView *textView_content = [[UITextView alloc] initWithFrame:CGRectMake(10, 5, 290, 200)];
    textView_content.textColor = RGB(93, 93, 93);
    textView_content.font = [UIFont fontWithName:@"Helvetica" size:15.0f];
    textView_content.text = _model_list.string_content;
    CGSize size_text = [self contentSizeOfTextView:textView_content];
    if(_model_list.array_img_small.count != 0){
        size_text.height = size_text.height + 55;
    }
    return size_text.height + 280 - IOS7_SIZE;
}

#pragma mark - 查看照片 -
/**
 *  查看照片
 */
-(void)didClickButton_addPhoto:(UIButton *)button{
    switch (button.tag) {
        case KWNQDetailCellTag_imageOne:{
            KWNPhotoDetailViewController *detail = [[KWNPhotoDetailViewController alloc] initWithDelegate:self];
            detail.int_tag = 1;
            if(_array_photo){
                [_array_photo removeAllObjects];
                [_array_photo addObjectsFromArray:_model_list.array_img];
            }
            else{
                NSMutableArray *array_photo = [NSMutableArray array];
                [array_photo addObjectsFromArray:_model_list.array_img];
                _array_photo = array_photo;
            }
            [self presentViewController:detail animated:YES completion:^{
                
            }];
        }break;
        case KWNQDetailCellTag_imageTwo:{
            if(_array_photo){
                [_array_photo removeAllObjects];
            }
            else{
                NSMutableArray *array_photo = [NSMutableArray array];
                _array_photo = array_photo;
            }
            NSArray *array_reverse = [[_model_list.array_img reverseObjectEnumerator] allObjects];
            [_array_photo addObjectsFromArray:array_reverse];
            KWNPhotoDetailViewController *detail = [[KWNPhotoDetailViewController alloc] initWithDelegate:self];
            detail.int_tag = 1;
            [self presentViewController:detail animated:YES completion:^{
                
            }];
        }break;
        default:
            break;
    }
}

#pragma mark - 点击游览图片 -
/**
 *  点击游览图片
 */
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    return _array_photo.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:_array_photo[index]]];
    return photo;
}

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index{
    switch (_array_photo.count) {
        case 1:{
            [(KWNPhotoDetailViewController *)photoBrowser scrollPageViewToIndex:index andBoolScroll:NO];
        }break;
        case 2:{
            [(KWNPhotoDetailViewController *)photoBrowser scrollPageViewToIndex:index andBoolScroll:YES];
        }break;
        default:
            break;
    }
}

@end
